﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Liquid.Collections;

namespace GapBufferTests {
	/// <summary>
	/// Summary description for Insertions
	/// </summary>
	[TestClass]
	public class Insertions {
		public TestContext TestContext { get; set; }

		[TestMethod]
		public void InsertSingle() {
			var buffer = new GapBuffer<int>(0);
			buffer.Insert(1);
			Assert.AreEqual(1, buffer.Count);
			Assert.IsTrue(buffer.ToArray().SequenceEqual(new int[] { 1 }), "Got incorrect sequence");
		}

		[TestMethod]
		public void InsertRange() {
			var buffer = new GapBuffer<int>(0);
			buffer.InsertRange(new int[] { 1, 2, 3 });
			Assert.AreEqual(3, buffer.Count);
			Assert.IsTrue(buffer.ToArray().SequenceEqual(new int[] { 1, 2, 3 }), "Got incorrect sequence");
		}

		[TestMethod]
		public void InsertSingleIntoMiddle() {
			var buffer = new GapBuffer<int>(0);
			buffer.InsertRange(new int[] { 1, 3 });
			Assert.AreEqual(2, buffer.Count);
			Assert.IsTrue(buffer.ToArray().SequenceEqual(new int[] { 1, 3 }), "Got incorrect sequence");
			buffer.Position = 1;
			buffer.Insert(2);
			Assert.AreEqual(3, buffer.Count);
			Assert.IsTrue(buffer.ToArray().SequenceEqual(new int[] { 1, 2, 3 }), "Got incorrect sequence");
		}

		[TestMethod]
		public void InsertRangeIntoMiddle() {
			var buffer = new GapBuffer<int>(0);
			buffer.InsertRange(new int[] { 1, 4 });
			Assert.AreEqual(2, buffer.Count);
			Assert.IsTrue(buffer.ToArray().SequenceEqual(new int[] { 1, 4 }), "Got incorrect sequence");
			buffer.Position = 1;
			buffer.InsertRange(new int[] { 2, 3 });
			Assert.AreEqual(4, buffer.Count);
			Assert.IsTrue(buffer.ToArray().SequenceEqual(new int[] { 1, 2, 3, 4 }), "Got incorrect sequence");
		}
	}
}
